package com.afinal.intelligencetrash.Model.db;

import android.content.Context;
import android.database.DatabaseErrorHandler;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * Created by cyy on 17-10-8.
 */

public class UserDBSQLHelper extends SQLiteOpenHelper {

    public static final String DB_NAME = "SimulateRemoteDB";
    public static final String TABLE_NAME = "User";
    public static final int VERSION = 1;

    public UserDBSQLHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        String sql = "CREATE TABLE "+TABLE_NAME+"(" +
                Column.ID+" INTEGER PRIMARY KEY AUTOINCREMENT," +
                Column.USER_NAME+ " VARCHAR(64) UNIQUE," +
                Column.PWD+ " VARCHAR(64)," +
                Column.DATA+" TEXT)";
        db.execSQL(sql);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        String sql = "DROP TABLE "+DB_NAME;
        db.execSQL(sql);
        onCreate(db);
    }

    public static class Column{
        public static final String ID = "id";
        public static final String USER_NAME = "username";
        public static final String PWD = "pwd";
        public static final String DATA = "dat";
    }
}
